package thread;

public class myRunnable implements Runnable {

    private volatile boolean active;
    private int temp = 0;
    public void run() {
        active = true;
        while (active) { // 第一行
            System.out.println("active is : "+ active + ", temp is : " + temp);
            temp++;
            if (temp == 100){
                break;
            }
        }
        if (active) {
            System.out.println("active is true...");
        } else {
            System.out.println("active is false...");
        }
    }
    public void stop() {
        active = false; // 第二行
        System.out.println("stop被调用，此时active为："+active+"，temp为："+ temp);
    }

    public static void main(String[] args) {
        System.out.println("process start!");
        myRunnable runnable1 = new myRunnable();
        System.out.println("process running!");
        runnable1.stop();
        myRunnable runnable2 = new myRunnable();
        runnable1.run();
        System.out.println("process running!");
        runnable1.stop();
        System.out.println("process end!");
    }
}

